package com.example.neusoft.zyfypt_wk;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText etuser, etpass, etpass2, etname, ettel;
    private Button btncamer, btnregitster, btnreturn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        init();
    }

    private void init() {
        etuser = (EditText) findViewById(R.id.etuser);
        etpass = (EditText) findViewById(R.id.etpass);
        etpass2 = (EditText) findViewById(R.id.etpass2);
        etname = (EditText) findViewById(R.id.etname);
        ettel = (EditText) findViewById(R.id.ettel);
        findViewById(R.id.btnregister).setOnClickListener(this);
        findViewById(R.id.btncamera).setOnClickListener(this);
        findViewById(R.id.btnreturn).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btnregister://注册
                register();
                break;
            case R.id.btncamera://拍照
                getPhoto();
                break;
            case R.id.btnreturn://返回
                finish();
                break;
        }
    }

    private void getPhoto() {
        //获取头像图片
        Toast.makeText(this, "获取头像", Toast.LENGTH_SHORT).show();
    }

    private void register() {
        String struser = etuser.getText().toString();
        String strpass = etpass.getText().toString();
        String strpass2 = etpass2.getText().toString();
        String strname = etname.getText().toString();
        String strtel = ettel.getText().toString();
        if (struser.equals("")) {
            Toast.makeText(this, "用户名不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        if (strpass.equals("")) {
            Toast.makeText(this, "密码不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        if (strpass2.equals("")) {
            Toast.makeText(this, "确认密码不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        if (strtel.equals("")) {
            Toast.makeText(this, "电话不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!strpass.equals(strpass2)) {
            Toast.makeText(this, "两次密码不一致", Toast.LENGTH_SHORT).show();
            return;
        }
        Toast.makeText(this, struser + "\n" + strpass + "\n" + strname + "\n" + strtel, Toast.LENGTH_SHORT).show();

    }
}
